package com.redshark.wmm.MeasurementProcessing;

import java.util.LinkedList;

/**
 * RMS Calculator
 * 
 * Keeps track of a set of values and will calculate the RMS value.
 * 
 * @author Brennan Ujcich
 * 
 */
public class RMSCalculator {
	private LinkedList<Double> ll = new LinkedList<Double>();
	private double total;

	public RMSCalculator() {
	}

	/**
	 * Adds new double to running value
	 * 
	 * @param d
	 *            Value to add
	 */
	public void add(double d) {
		double squared = Math.pow(d, 2);
		ll.add(squared);
		total += squared;
	}
	
	public int count(){
		return ll.size();
	}

/*	*//**
	 * @return True if there are enough values to calculate a rms value
	 *//*
	boolean isFull() {
		if (ll.size() == SIZE) {
			return true;
		} else {
			return false;
		}
	}*/

	/**
	 * Removes all elements from the Calculator
	 */
	public void clear() {
		ll.clear();
		total = 0.0;
	}

	/**
	 * Returns rms value of previous values added
	 * 
	 * @return RMS Value
	 * @throws ScopeMessageException
	 */
	public double calculateRMS() {
		double rms;

		rms = Math.sqrt(total/ll.size());

		return rms;
	}

/*	public class RMSNotAvailableException extends Exception {

		public RMSNotAvailableException(String message) {
			super(message);
		}

		public RMSNotAvailableException(String message, Throwable throwable) {
			super(message, throwable);
		}

	}*/

}
